/*
 *  PotentialField.h
 *  powaah
 *
 *  Created by Tim Uusitalo on 4/3/11.
 *  Copyright 2011 __MyCompanyName__. All rights reserved.
 *
 */

#ifndef POTENTIAL_FIELD_H

#define POTENTIAL_FIELD_H

#include "StdInclude.cpp"

#include "Charge.h"

#include "CarState.h"

#include "MathUtility.h"

#include "DriverOption.h"
/**
 * Coulomb's law - P = C1*C2 / O^2
 *
 *
 *
 *
 */


class PotentialField
{

protected:
	typedef std::map<int, Charge> ChargeContainer;

public:
	/// Constructor
	PotentialField();
	
	/// Destructor
	virtual ~PotentialField();
	
	/**
	 * Inserts a charge into the field
	 */
	void insertCharge(const Charge& charge, const int pos);

	/**
	 * A virtual void NULL function, this must be used in the subclasses
	 */
	virtual void update(CarState& cs, const float dt) = 0;

	/**
	 * Updates the internal carstate to the current one
	 */
	void updateState(CarState& cs);

	/**
	 * Finds the highest charge in the field
	 */
	const Charge getHighestCharge(int* const pos = NULL);
	
	/**
	 * Finds the lowest charge in the field
	 */
	const Charge getLowestCharge(int* const pos = NULL);
	
	/**
	 * Finds the charge with the higest potential-value
	 */
	const Charge getChargeWithHighestPotential(int* const pos = NULL);
	
	/**
	 * @return - Finds the charge at position pos
	 */
	const Charge getChargeAt(const int pos);
	
	void clear();

	virtual void calculatePotentialForOptions(DriverOption* const options, unsigned int size);
	
	void calculatPotentialForOptionsSquareRoot(DriverOption* const options, unsigned int size);

	void print();
	
	const unsigned int size() const;
protected:
	
	ChargeContainer field;
	
	CarState current;

};


#endif
